package initialize

import (
	"fmt"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/producer"
	"go.uber.org/zap"
	"sale_system/order_srv/global"
)

func InitProducer() {
	address := fmt.Sprintf("%s:%d", global.ServerConfig.RocketMqInfo.Host, global.ServerConfig.RocketMqInfo.Port)
	var err error

	// 用来监听本地事务操作，并接收本地事务的数据

	global.ProducerOrderTimeout, err = rocketmq.NewProducer(producer.WithGroupName("sale-order-timeout"), producer.WithNameServer([]string{address}))
	if err != nil {
		zap.S().Info("获取生产者对象失败, ", err.Error())
		panic(err)
	}

	if err = global.ProducerOrderTimeout.Start(); err != nil {
		zap.S().Info("启动生产者对象失败，%s ", err.Error())
		panic(err)
	}
	
}
